package com.zq.it.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.zq.it.dao.FileSourceDao;
import com.zq.it.pojo.FileSource;

public  class FileSourceDaoImpl extends BaseDao<FileSource> implements FileSourceDao {

	@Override
	public void deleteSourcesByHql(String hql) {
		getHibernateTemplate().bulkUpdate(hql);
	}

	@Override
	public List<FileSource> findSourcesByNumber(final int number) {
		return getHibernateTemplate().executeFind(new HibernateCallback(){
			@Override
			public  List<FileSource> doInHibernate(Session session)throws HibernateException, SQLException {
				Query query = session.createQuery("from FileSource");
				query.setFirstResult(0);
				query.setMaxResults(number);
				return query.list();
			}
		});
	}
}
